package stz.flash.main;

import stz.flash.main.flashlight.model.Flashlight;
import stz.flash.option.OptionScreen;
import net.rim.device.api.system.SystemListener2;


public class BacklightOnOffListener implements SystemListener2{
	
	public void backlightStateChange(boolean on) {
		
		if (ScreenHandle.getIns().isDisplayed() == false || OptionScreen.isOptionDisplayed())
			return;
		
		if (on) {

			new Thread() {
				public void run() {
					joinFlashlightThread();
					loadLastestMode();
				}
			}.start();
		}
	}
	
	private void joinFlashlightThread() {
		if (Flashlight.getThread() == null)
			return;
		try {
			Flashlight.getThread().join();
		} catch (InterruptedException e) {
		}
	}
	
	private void loadLastestMode() {
		ModeChangeHandler.loadLatestMode();
	}

	public void batteryGood() { }
	public void batteryLow() { }
	public void batteryStatusChange(int status) { }
	public void powerOff() { }
	public void powerUp() { }
	public void cradleMismatch(boolean mismatch) { }
	public void fastReset() { }
	public void powerOffRequested(int reason) { }
	public void usbConnectionStateChange(int state) { }
}
